﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Register
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%using (Html.BeginForm("go", "register", FormMethod.Post, new { ID = "target" }))
      { %>
    <table>
        <tr>
            <td>
                First Name
            </td>
            <td>
                <%=Html.TextBox("firstname")%>
                <br />
                <%=Html.ValidationMessage("firstname")%>
            </td>
        </tr>
        <tr>
            <td>
                Last Name
            </td>
            <td>
                <%=Html.TextBox("lastname")%>
                <br />
                <%=Html.ValidationMessage("firstname")%>
            </td>
        </tr>
        <tr>
            <td>
                E-mail
            </td>
            <td>
                <%=Html.TextBox("email")%>
            </td>
        </tr>
        <tr>
            <td>
                Password
            </td>
            <td>
                <%=Html.Password("password")%>
            </td>
        </tr>
        <tr align="center">
            <td colspan="2">
                <input type="submit" value="Register" id="Register" onclick="return DoAjaxSubmit(this);" />
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        function DoAjaxSubmit(btnClicked) {
            var form = $(btnClicked).parents('form');
            $.ajax({
                type: "POST",
                url: form.attr('action'),//'<%=ResolveUrl("~/register/go") %>',
                data: form.serialize(),
                error: function (xhr, status, error) {
                },
                success: function (response) {
                    if (response != null) {
                        if (!response.Successful) {
                            alert("Please fill the details Correctly");
                            return false;
                        }
                        else {
                            window.location.href = "/register/package";
                        }
                    }
                }
            });
            return false;
        }
    </script>
    <%} %>
</asp:Content>
